import { userInfoStore } from '@/pinia/userInfo'
import hasPermission from '@/utils/hasPermission'

const vButtonAuth = {
  // 及他自己的所有子节点都挂载完成后调用
  mounted(el, binding, vnode) {
    const userInfo = userInfoStore()
    const permission = binding.value
    // 判断用户是否有权限
    if (!hasPermission(userInfo.userAuth, permission)) {
      return el.parentNode.removeChild(el)
    }
  },
  // 绑定元素的父组件更新前调用
  beforeUpdate(el, binding, vnode, prevVnode) {
    // console.log(el.parent)
  }
}

export default vButtonAuth
